﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DAO;

namespace QLKS
{
    public partial class frmXemPhongDaThue : Form
    {
        public frmXemPhongDaThue()
        {
            InitializeComponent();
        }

        private void frmXemPhongDaThue_Load(object sender, EventArgs e)
        {
            listView1.Items.Clear();

            DataTable dt = PhieuThuePhongDAO.Get();
            int j = 1;
            foreach (DataRow dr in dt.Rows)
            {
                ListViewItem lv = new ListViewItem(j.ToString());

                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    lv.SubItems.Add(dr[i].ToString());
                }
                listView1.Items.Add(lv);
                j++;
            }
        }

        private void txtTenKhachHang_TextChanged(object sender, EventArgs e)
        {
            if (txtTenKhachHang.Text != "")
            {
                //cbbMaKhachHang.Items.Clear();
                cbbMaKhachHang.Text = "Chọn khách thanh toán";
                DataTable dt1 = KhachHangDAO.MaKTheoTen(txtTenKhachHang.Text);
                foreach (DataRow dr1 in dt1.Rows)
                {
                    cbbMaKhachHang.Items.Add(dr1[0]);
                }
            }
        }

        private void cbbMaKhachHang_SelectedIndexChanged(object sender, EventArgs e)
        {
            int ma = int.Parse(cbbMaKhachHang.Text);
            DataTable dt = KhachHangDAO.KhachTheoMa(ma);
            DataRow dr = dt.Rows[0];
            txtTenKhachHang.Text = dr["TenKhachHang"].ToString();
            txtCMND.Text = dr["CMND"].ToString();
            txtDiaChi.Text = dr["DiaChi"].ToString();

            DataTable dt1 = PhieuThuePhongDAO.LayPhieuThueTheoMa(ma);
            int j = 1;
            listView1.Items.Clear();
            foreach (DataRow dr1 in dt1.Rows)
            {
                ListViewItem lv = new ListViewItem(j.ToString());

                for (int i = 0; i < dt1.Columns.Count; i++)
                {
                    lv.SubItems.Add(dr1[i].ToString());
                }
                listView1.Items.Add(lv);
                j++;
            }
        }
    }
}
